package com.cyj.springbootservice.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyj.springbootservice.api.entity.Aerial;
import com.cyj.springbootservice.api.entity.AerialLatitudeAndLongitude;
import com.cyj.springbootservice.api.entity.enums.AerialMode;
import com.cyj.springbootservice.api.entity.enums.Motion;
import com.cyj.springbootservice.api.vo.AerialVO;
import com.cyj.springbootservice.mapper.AerialMapper;
import com.cyj.springbootservice.service.IAerialLatitudeAndLongitudeService;
import com.cyj.springbootservice.service.IAerialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @Author C_Y_J
 * @create 2021/10/7 13:54
 **/
@Service
public class AerialServiceImpl extends ServiceImpl<AerialMapper, Aerial> implements IAerialService {

    @Autowired
    private AerialMapper aerialMapper;

    @Autowired
    private IAerialLatitudeAndLongitudeService aerialLatitudeAndLongitudeService;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean sumbit() {
        Aerial aerial = new Aerial();
        aerial.setName("新建航拍");
        aerial.setAerialMode(AerialMode.SLANT);
        aerial.setFlightHeight(50);
        aerial.setTakeoffSpeed(5);
        aerial.setLineSpeed(20);
        aerial.setElevationOptimization(false);
        aerial.setCompleteTheAction(Motion.HOVER);
        aerial.setLateralOverlapRatio(14);
        aerial.setCourseOverlapRate(13);
        aerial.setMainRouteAngle(12);
        aerial.setTiltAngle(11);
        aerial.setArgin(10);
        aerial.setUrl("https://");
        aerial.setAddress("梁山");
        aerialMapper.insert(aerial);
        Long id = aerial.getId();

        AerialLatitudeAndLongitude aerialLatitudeAndLongitude = new AerialLatitudeAndLongitude();
        aerialLatitudeAndLongitude.setLongitude(555555.5555D);
        aerialLatitudeAndLongitude.setLatitude(666666.6666D);
        aerialLatitudeAndLongitude.setFlagBit(1);

        AerialLatitudeAndLongitude aerialLatitudeAndLongitude2 = new AerialLatitudeAndLongitude();
        aerialLatitudeAndLongitude2.setLongitude(666666.6666D);
        aerialLatitudeAndLongitude2.setLatitude(777777.7777D);
        aerialLatitudeAndLongitude2.setFlagBit(2);

        AerialLatitudeAndLongitude aerialLatitudeAndLongitude3 = new AerialLatitudeAndLongitude();
        aerialLatitudeAndLongitude3.setLongitude(777777.7777D);
        aerialLatitudeAndLongitude3.setLatitude(888888.8888D);
        aerialLatitudeAndLongitude3.setFlagBit(3);
        List<AerialLatitudeAndLongitude> aerialLatitudeAndLongitudes = Arrays.asList(aerialLatitudeAndLongitude, aerialLatitudeAndLongitude2, aerialLatitudeAndLongitude3);

        List<AerialLatitudeAndLongitude> collect = aerialLatitudeAndLongitudes.stream().map(s -> s.setAerialId(id)).collect(Collectors.toList());

        return aerialLatitudeAndLongitudeService.saveBatch(collect);
    }

    @Override
    public IPage<AerialVO> findByPage(IPage<AerialVO> IPage, Aerial aerial) {
        return IPage.setRecords(aerialMapper.findByPage(IPage, aerial));
    }

    @Override
    public IPage<AerialVO> findByPage2(IPage<AerialVO> IPage, Aerial aerial) {
        return IPage.setRecords(aerialMapper.findByPage2(IPage, aerial));
    }

}
